package brc.symbolTable;

import java.util.Hashtable;

public class SymbolTable extends Hashtable<String, SymbolEntry> {
	private static final long serialVersionUID = 695362684321765864L;
	private static SymbolTable singletonHolder;
	
	private static SymbolTable getSingletonHolder() {
		if (SymbolTable.singletonHolder == null) {
			SymbolTable.singletonHolder = new SymbolTable();
		}
		return SymbolTable.singletonHolder;
	}
	
	private SymbolTable() {
		super();
	}
	
	private boolean put(String varName, int type) {
		if (!this.containsKey(varName)) {
			this.put(varName, new SymbolEntry(varName, type));
			return true;
		}
		else {
			return false;
		}
	}

	public static SymbolEntry getVariableEntry(String varName) {
		return SymbolTable.getSingletonHolder().get(varName);
	}
	public static boolean existsVariable(String varName) {
		return SymbolTable.getSingletonHolder().containsKey(varName);
	}
	public static boolean putVariable(String varName, int type) {
		return SymbolTable.getSingletonHolder().put(varName, type);
	}
	public static void print(){
		System.out.println(SymbolTable.singletonHolder);
	}
}
